package mysql

import (
	"bluebell/models"
	"database/sql"
	"errors"
)

func GetCommunityList() (list []*models.Community, err error) {
	sqlStr := "SELECT * FROM community"
	if err = db.Select(&list, sqlStr); err != nil {
		if err == sql.ErrNoRows {
			err = nil
		}
	}
	return
}

func GetCommunityDetailByID(id int64) (data *models.CommunityDetail, err error) {
	sqlStr := `select id,name,introduction,create_time from community where id = ?`
	data = new(models.CommunityDetail)
	if err = db.Get(data, sqlStr, id); err != nil {
		if err == sql.ErrNoRows {
			err = errors.New("无效ID")
		}
	}
	return
}
